package model

import (
	"errors"
	"gorm.io/gorm"
	"io"
	"strings"
)

type SensitiveWord struct {
	Model

	Word string `json:"word"`
}

func (m *SensitiveWord) TableName() string {
	return "sensitive_word"
}

func GetSensitiveWords() (io.Reader, error) {
	var rows []SensitiveWord

	err := db.Find(&rows).Error
	if err != nil {
		if errors.Is(err, gorm.ErrRecordNotFound) {
			return nil, nil
		} else {
			return nil, err
		}
	}

	words := ""
	for _, value := range rows {
		words = words + value.Word + "\n"
	}
	return strings.NewReader(words), nil
}
